package com.zhuhao.basic.proxy.cglib;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 实现MethodInterceptor接口
 * @Author haozhu7
 * @Date 2025/5/23 10:57
 **/
public class MyMethodInterceptor implements MethodInterceptor {
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("Before method invocation");
        Object result = methodProxy.invokeSuper(o, objects);
        System.out.println("After method invocation");

        if (result instanceof String) {
            return result + " : Proxy";
        }

        return result;
    }
}